package cn.push.embed.core.utils;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import cn.push.embed.utils.CommonUtils;


/**
 * Author：Ht
 * Create time：2015/8/19 9:03
 * Email：hunter_android@163.com
 * Description：日志管理器
 */

public class Logger {
    private static final String TAG = "LPUSH:";


    /**
     * 是否为开发者模式(开发模式打印LOG,非开发模式不打印LOG)
     */
    private static boolean mDebug = true;//false关闭  true打开

    public static boolean ismDebug() {
        return mDebug;
    }

    public static void setmDebug(boolean mDebug) {
        Logger.mDebug = mDebug;
    }

    private Logger() {
    }

    /**
     * 打印info级别的log
     *
     * @param msg
     */
    public static void i(String msg) {
        if (mDebug) {
            Log.i(TAG + "  Log", msg);
        }
    }

    /**
     * 打印info级别的log
     *
     * @param msg
     */
    public static void d(String msg) {
        if (CommonUtils.isEmpty(msg)){
            return;
        }
        if (mDebug) {
            Log.d(TAG + "  Log", msg);
        }
        Bundle bundle=new Bundle();
        bundle.putString("message","Log:  "+msg);
        Message message=new Message();
        message.setData(bundle);
        message.what=1;
      //  MainActivity.handler.sendMessage(message);

    }

    /**
     * 打印info级别的log
     *
     * @param msg
     */
    public static void d(String tag, String msg) {
        if (mDebug) {
            Log.d(tag, msg);
        }

    }

    public static void i(String tag, String msg) {
        if (mDebug) {
            Log.i(tag, msg);
        }
    }

    /**
     * 打印error级别的log
     *
     * @param msg
     */
    public static void e(String msg) {
        if (mDebug) {
            Log.e(TAG + "  Log", msg);
        }
    }

    public static void e(String tag, String msg) {
        if (mDebug) {
            Log.e(tag, msg);
        }
    }

    public static void showLogToText(TextView tvLog, String content) {
        StringBuilder log = new StringBuilder();
        String line=tvLog.getText().toString();
        if (line.length()>10000){
            line=line.substring(0,7000);
        }
        log.append(content);
        log.append('\n');
        log.append(line);
        tvLog.setText(log.toString());
    }


}
